package org.myspringframework.mvc.type;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

/**
 * org.myspringframework.mvc.type <br>
 * 存储处理完后的结果数据，以及显示该数据的视图
 *
 * @author jaymin
 * @since 2021/5/23
 */
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class ModelAndView {
    /**
     * 页面所在的路径
     */
    private String view;
    /**
     * 页面data数据
     */
    private Map<String, Object> model = new HashMap<>();

    public ModelAndView setView(String view) {
        this.view = view;
        return this;
    }

    /**
     * modelAndView.setView("addHeadline.jsp").addViewData("a","b");
     * @param attributeName
     * @param attributeValue
     * @return
     */
    public ModelAndView addViewData(String attributeName, Object attributeValue) {
        model.put(attributeName, attributeValue);
        return this;
    }
}
